let ajax = getApp().globalData.ajax;
const util = require('../../utils/util.js')
Page({
  /**
   * 页面的初始数据
   */
  data: {
    walletDetails: [],
    skip: 0,
    take: 7,
    hasNext: false,
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    let json = {
      token: wx.getStorageSync('Cookie'),
      skip: this.data.skip,
      take: this.data.take,
    };
    this.getData(json);
  },
  getData (json) {
    ajax('user/details', json, ).then(res => {
      let walletDetails = res.data;
      walletDetails.forEach(item => {
        item.money = (item.money).toFixed(2);
        switch (item.reason.orderType) {
          case 'CHARGE':
            item.statusRes = '充值'
            break
          case 'PAY':
            item.statusRes = '支付'
            break
          case 'WITH_DRAW':
            item.statusRes = '提现'
            break
          case 'RE_BACK_WITH_DRAW':
            item.statusRes = '提现失败，退提现的钱'
            break
          case 'DENY_ORDER':
            item.statusRes = '订单被拒绝'
            break
          case 'FINISH':
            item.statusRes = '完成订单'
            break
          case 'AUTOFINISH':
            item.statusRes = '订单自动完成'
            break
          case 'AUTOREFUND':
            item.statusRes = '订单自动取消'
            break
          case 'UNKNOWN':
            item.statusRes = '其他'
            break
          default:
            item.statusRes = '其他'
            break
        }
        item.time_res = item.time.toDateString();
      });
      walletDetails = this.data.walletDetails.concat(walletDetails);
      this.setData({ walletDetails });
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {


  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

    let skip = this.data.skip;
    skip += this.data.take;
    this.setData({
      skip,
    })
    let json = {
      token: wx.getStorageSync('Cookie'),
      skip: this.data.skip,
      take: this.data.take,
    }
    this.getData(json)
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})